*******************************************************
* Table A2 onwards: Regressions on Non-Cognitive Scores 
*******************************************************

preserve 
*-------------------------
*PANEL A: Without any controls
*-------------------------

* Set 1: Standardized Test Scores
est clear
foreach var in ps $parentsupp {

	di "`var' without controls"
	*1) Without any controls
	*local var "time_study_out"
	gen Baseline = `var'
	la var Baseline "Baseline"
	gen miss = missing(Baseline)
	replace Baseline = 0 if missing(Baseline)
	

	*Running the statistical inference
	qui ritest treatment _b[treatment], cluster(id_school) reps($reps): ///
	reg el_`var' treatment Baseline miss, vce(robust)
	matrix pvalues = r(p)
	gen temp = pvalues[1,1]

	qui eststo panela_`var': bootstrap, seed(2905) cl(id_school) reps($reps) nodots: qui reg el_`var' treatment Baseline miss
	*eststo: reg el_`var' treatment Baseline miss, vce(robust)
	qui test treatment 
	qui estadd scalar pvalreg = round(r(p),0.001)
	qui summ el_`var' if treatment == 0 & miss == 0
	qui estadd scalar mean = r(mean)
	qui estadd local ife = "No", replace
	qui estadd local sfe = "No", replace
	qui estadd local regtype = "OLS", replace
	qui estadd scalar rsq = e(r2)
	
	qui summ temp
	qui estadd scalar pvalri= r(mean)
	drop Baseline miss temp
}

*----------------------------------------
*PANEL B: With individual and school controls
*----------------------------------------
* Set 1: Level increases
* Set 1: Standardized Test Scores

foreach var in ps $parentsupp {

	di "`var' without controls"
	*1) Without any controls
*	local var "readcode"
	gen Baseline = `var'
	la var Baseline "Baseline"
	gen miss = missing(Baseline)
	replace Baseline = 0 if missing(Baseline)
	

	*Running the statistical inference
	qui ritest treatment _b[treatment], cluster(id_school) reps($reps): ///
	reg el_`var' treatment Baseline miss $indcontrols $schcontrols, vce(robust)
	matrix pvalues = r(p)
	gen temp = pvalues[1,1]

	eststo panelb_`var': qui bootstrap, seed(2905) cl(id_school) reps($reps) nodots: qui reg el_`var' treatment Baseline miss $indcontrols $schcontrols
*	eststo: reg el_`var' treatment Baseline miss, vce(robust)
	qui test treatment 
	qui estadd scalar pvalreg = round(r(p),0.001)
	qui summ el_`var' if treatment == 0 & miss == 0
	qui estadd scalar mean = r(mean)
	qui estadd local ife = "Yes", replace
	qui estadd local sfe = "Yes", replace
	qui estadd local regtype = "OLS", replace
	qui estadd scalar rsq = e(r2)
	
	qui summ temp
	qui estadd scalar pvalri= r(mean)
	drop Baseline miss temp
}


# delimit ;
esttab  panela* using "$tables/TableA2.tex", replace
keep(treatment Baseline)
cells(b(fmt(%5.2f) star) se(fmt(%5.2f) par))
starlevels(* .10 ** .05 *** .01) 
mgroups("Total" "Events" "Homework" "School" "Talk", pattern(1 1 1 1 1)
span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) 
nomtitles
posthead("\midrule \multicolumn{6}{l}{\textit{\textbf{Panel A. Without individual and school controls}}} \\ \midrule")
postfoot("")
stats(pvalreg pvalri rsq, labels("p-val (OLS)" "p-val (RI)" "\midrule R2") ///
fmt(2 2 2)) ///
collabels(none) label booktabs nonotes
;

# delimit ;
esttab  panelb* using "$tables/TableA2.tex", append
keep(treatment) ///
cells(b(fmt(%5.2f) star) se(fmt(%5.2f) par)) /// 
starlevels(* .10 ** .05 *** .01) ///
prehead("") ///
posthead("\midrule \multicolumn{6}{l}{\textit{\textbf{Panel B. With individual and school controls}}} \\ \midrule")
stats(pvalreg pvalri mean rsq N, labels("p-val (OLS)" "p-val (RI)" "\midrule Control mean" "\midrule R2" "N") ///
fmt(2 2 2 2 0)) ///
collabels(none) mlabels(none) nonumbers label booktabs nonotes nomtitles;
#delimit cr	

restore 